<template>
	<view class="container">
		<view class="title">
			<text>标题：</text>
			<input type="text" v-model="title" placeholder="请输入标题…" placeholder-class="lc"/>
		</view>
		<view class="content">
			<text>内容：</text>
			<textarea v-model="content" placeholder="请输入内容…" placeholder-class="lc"/>
		</view>
		<view class="upload">
			<uni-file-picker v-model="other_card" fileMediatype="image" mode="grid"
				@select="select" @progress="progress" @success="success" @fail="fail" />
		</view>
		<view class="tijiao" @click="tijiao()">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				other_card: [],
				title:"",
				content:"",
				token:""
			}
		},
		created() {
			uni.getStorage({
				key: 'user_info',
				success: (res) => {
					this.token = res.data.token;
				},
				fail: (res) => {
					uni.redirectTo({
						url: '../../login/auth'
					});
				}
			});
		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
			},
			// 获取上传进度
			progress(e) {
				console.log('上传进度：', e)
			},
			
			// 上传成功
			success(e) {
				console.log('上传成功')
			},
			
			// 上传失败
			fail(e) {
				console.log('上传失败：', e)
			},
			tijiao() {
				console.log(this.other_card)
				uni.showLoading({
					title:"提交中...",
					mask:true
				})
				uni.request({
					url: `https://mx.acktechnologies.com.cn/api/wxapp/mine/index/suggestion`,
					data: {
						"token": this.token,
						"content":this.content,
						"images":this.other_card,
						"title":this.title
					},
					method: 'GET',
					success: res => {
						if (res.data.code === 1) {
							uni.hideLoading();
							uni.showToast({
								title:res.data.msg
							})
						} else if (res.data.code === 403) {
							uni.redirectTo({
								url: '../../login/auth'
							});
						} else {
							uni.showToast({
								title: '服务器开小差了呢，请您稍后再试',
								icon: 'none'
							})
						}
					},
					fail: () => { //接口请求失败的处理
						uni.showToast({
							title: '服务器开小差了呢，请您稍后再试',
							icon: 'none'
						})
					},
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.container{
		font-family: SourceHanSansCN-Normal, SourceHanSansCN;
	}
	.title{
		width: 670rpx;
		height: 114rpx;
		background: #FFFFFF;
		border-radius: 5px;
		border: 1px solid #D8D8D8;
		margin: 40rpx auto;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 21px;
		box-sizing: border-box;
		text{
			font-size: 15px;
			color: #333333;
		}
		input{
			flex-grow: 1;
		}
		
	}
	.content{
		width: 670rpx;
		height: 280rpx;
		background: #FFFFFF;
		border-radius: 5px;
		border: 1px solid #D8D8D8;
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		padding-left: 21px;
		padding-top: 40rpx;
		box-sizing: border-box;
		margin: 0 auto;
		text{
			font-size: 15px;
			color: #333333;
		}
		textarea{
			width: 510rpx;
			height: 240rpx;
			flex-grow: 1;
		}
	}
	.lc{
		font-size: 15px;
		color: #D6D6D6;
	}
	.upload{
		margin: 40rpx;
	}
	.tijiao{
		width: 700rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background: linear-gradient(90deg, #9BDFB5 0%, #84DFD1 100%);
		border-radius: 40rpx;
		margin: 60px auto 0 auto;
		font-size: 18px;
		color: #FFFFFF;
	}
</style>
